define([], function() {
	'use strict';
	var BaseToolHandler = function(toolName) {
		if (!toolName) throw 'toolHandler should have name'; 
		this.name = toolName;
		this.isActived = false;		
		this.eventHandler = [];
		this.cursorClass = '';

		this.canActive = function(curToolName){
			return (curToolName == this.name);
		};
	};			

	var fn = BaseToolHandler.prototype;

	fn.doActive = function(pageContainer) {
		if (this.isActived) return;
		this.isActived = true;
		this.pageContainer = pageContainer;		
		this.bindEvent();	
		console.log('active', this.name);
	};

	fn.doDeactive = function() {
		if (!this.isActived) return;
		this.isActived = false;
		this.unBindEvent();	
		this.pageContainer = null;		
	};

	fn.bindEvent = function () {
		var _pageContainer = this.pageContainer;
		if (!_pageContainer) return;
		angular.forEach(this.eventHandler, function(handler, key) {
			_pageContainer.on(handler[0], handler[1], handler[2]);
		});		
	};

	fn.unBindEvent = function () {
		var _pageContainer = this.pageContainer;
		if (!_pageContainer) return;
		angular.forEach(this.eventHandler, function(handler, key) {
			_pageContainer.off(handler[0], handler[1], handler[2]);
		});		
	};

	fn.active = function(curToolName, pageContainer) {
		if (this.canActive(curToolName)){
			this.doActive(pageContainer);
		}
		else{
			this.doDeactive();
		}
	};

	fn.on = function(){
		this.eventHandler.push($.makeArray(arguments));
		return this;
	};

	fn.setPageContainerCursor = function(_cursorClass){
		this.pageContainer.removeClass(this.cursorClass);		
		if (Environment.ie || Environment.ieAtLeast11) {
			this.cursorClass = _cursorClass + 'ie';
		} else {
			this.cursorClass = _cursorClass;
		}
		this.pageContainer.addClass(this.cursorClass);
	};

	return BaseToolHandler;
});